home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / vgfx10.zip / GUYDEMO.PAS < prev    next >
Pascal/Delphi Source File  |  1994-12-01  |  15KB  |  544 lines

  1. { VGFX: Manual "Page-Flipping" Demo!
  2.  
  3.   GUYDEMO.PAS was written to show you the difference between using
  4.   the Update procedure for "page-flipping" animations and programming
  5.   the "page-flips" manually.  As you will see the Update engine is
  6.   running much slower than the manual engine.  This is because Update
  7.   is redrawing the whole screen to keep the background updated.  By
  8.   manually keeping track of the "page-flips" you achieve a lot faster
  9.   animation.  The disadvantage to manually "page-flipping" is that a
  10.   lot more programming is required.  If you are using VGFX and
  11.   writing a game that requires a 486SX-20 or better, than I would
  12.   suggest using Update.  If your game requires a 386SX or better than
  13.   you may want to use manual "page-flipping".  Another disadvantage
  14.   to manual "page-flipping" is that some routines in VGFX do support
  15.   the manual method.  For example, the mouse routines.  Although you
  16.   can use MShow and MPress, MMove will not work.  If you call MMove
  17.   without Update, the mouse will leave "trails" behind.  You will have
  18.   to keep track of that on your own.  This may seem like a bit of a
  19.   drag, but if you have already figured out the code for manually
  20.   updating your game sprites (animations) then you can easily use the
  21.   same method on the mouse cursor.  The are two global variables in
  22.   VGFX, mX and mY.  These two variables are the current mouse coords.
  23.   We would suggest creating two var's: lastX and lastY.  Here is some
  24.   theory on to as how you could do that.  We have not tested but it
  25.   seems straightforward.
  26.  
  27.   *** THEORY ***
  28.   ==============
  29.  
  30.   mX = 10
  31.   mY = 10
  32.  
  33.   lastX = mX
  34.   lastY = mY
  35.  
  36.   start of the loop
  37.  
  38.         Undraw the mouse cursor
  39.  
  40.         MMove is called - this gets the new mouse position
  41.           * New Mouse position was calculated by MMove. mX and mY
  42.             both equal the new mouse position (if it was moved).
  43.  
  44.         lastX = mX
  45.         lastY = mY
  46.  
  47.   end of loop                                                           }
  48.  
  49. program VGFX_Demo;
  50.  
  51.  
  52. uses VGFX, crt, dos;
  53.  
  54.  
  55. { Declare our memory needed for sprites }
  56. type
  57.     guyc = array[1..975] of byte;
  58.     tree = array[1..6059] of byte;
  59.  
  60. { Misc. demo variables }
  61. var
  62.    tmp      : integer;
  63.    x, y     : integer;
  64.    key      : char;
  65.    man      : array[1..8] of ^guyc;
  66.    backg    : ^guyc;
  67.    btree    : ^tree;
  68.  
  69.  
  70. { Small little 'RPG-game' like demo }
  71. { - - - - - - }
  72. Procedure Game_SampleDemo;
  73. Var
  74.    WalkL, WalkR,
  75.    StandL, StandR: Boolean;
  76.    Quit          : Boolean;
  77.    fname         : string;
  78.    cnum,
  79.    speed         : byte;
  80.    tmpPage       : byte;
  81.  
  82. Begin
  83.  
  84.      { Allocate some memory for our little guy }
  85.      for tmp := 1 to 8 do
  86.          new (man[tmp]);
  87.  
  88.      new (btree);
  89.  
  90.      { Set the palette to black }
  91.      BlankPalette;
  92.      SetWorkPage (1);
  93.  
  94.  
  95.      { Load-up the animation cells into memory }
  96.      for tmp := 1 to 8 do
  97.      begin
  98.           fname := 'cel000' + INT2STR(tmp) + '.pcx';
  99.  
  100.           showpcx (fname, 1, 1);
  101.           GetImage (man[tmp]^, 145, 38, 25, 39);
  102.      end;  { end for\do }
  103.  
  104.  
  105.      { Load-up the tree as we will use it later }
  106.      showpcx ('bigtree2.pcx', 1, 1);
  107.      GetImage (btree^, 1, 1, 73, 83);
  108.  
  109.  
  110.      { Set the palette to black }
  111.      BlankPalette;
  112.  
  113.      { Clear the video pages }
  114.      SetWorkPage (1);
  115.      clearscreen (0);
  116.      SetWorkPage (2);
  117.      clearscreen (0);
  118.  
  119.      { Initialize the mouse driver }
  120.      MInit;
  121.  
  122.      { Make the mouse cursor visible }
  123.      MShow (1);
  124.  
  125.      { Show message box #1 }
  126.      showpcx ('msg1b.pcx', 1, 1);
  127.      showpcx ('msg1b.pcx', 0, 2);
  128.  
  129.      FlushKB;
  130.  
  131.      repeat
  132.            { Update Mouse }
  133.            MMove;
  134.  
  135.            { Check for mouse clicks }
  136.            MClick(0);
  137.  
  138.            { Update display }
  139.            Update;
  140.      until ((keypressed) or (btnP<>0));
  141.  
  142.  
  143.      { Show message box #2 }
  144.      showpcx ('msg2b.pcx', 1, 1);
  145.      showpcx ('msg2b.pcx', 1, 2);
  146.  
  147.      FlushKB;
  148.  
  149.      repeat
  150.            { Update Mouse }
  151.            MMove;
  152.  
  153.            { Check for mouse clicks }
  154.            MClick(0);
  155.  
  156.            { Update display }
  157.            Update;
  158.      until ((keypressed) or (btnP<>0));
  159.  
  160.  
  161.      { Fade-out the palette }
  162.      FadeOut (1, 1, 0);
  163.  
  164.      { Set the palette to black }
  165.      BlankPalette;
  166.  
  167.      { Clear the video pages }
  168.      SetWorkPage (1);
  169.      clearscreen (0);
  170.      SetWorkPage (2);
  171.      clearscreen (0);
  172.  
  173.      { Load-up the background scene on both video pages }
  174.      showpcx ('demo.pcx', 1, 1);
  175.      showpcx ('demo.pcx', 1, 2);
  176.  
  177.      { Put the little guy on the screen }
  178.      PutClip (man[1]^, 100, 80, 25, 39);
  179.  
  180.      { Restore the palette }
  181.      RestorePalette;
  182.  
  183.  
  184.      x     := 100;
  185.      y     := 80;
  186.      cnum  := 1;
  187.      speed := 2;
  188.      StandL:= TRUE;
  189.      StandR:= FALSE;
  190.      WalkL := FALSE;
  191.      WalkR := FALSE;
  192.      Quit  := FALSE;
  193.  
  194.      FlushKB;
  195.      repeat
  196.            if (keypressed) then
  197.            begin
  198.                 key := readkey;
  199.  
  200.                 if (upcase(key) = 'Q') then Quit := TRUE;
  201.  
  202.                 { Increase guy's speed }
  203.                 if (key = '+') then
  204.                 begin
  205.                      inc(speed);
  206.                      if (speed > 50) then
  207.                      begin
  208.                           speed := 50;
  209.                           sound (900);
  210.                           delay (10);
  211.                           nosound;
  212.                      end;  { end if\then }
  213.                 end;  { end if\then }
  214.  
  215.                 { Decrease guy's speed }
  216.                 if (key = '-') then
  217.                 begin
  218.                      dec(speed);
  219.                      if (speed < 1) then
  220.                      begin
  221.                           speed := 1;
  222.                           sound (900);
  223.                           delay (10);
  224.                           nosound;
  225.                      end;  { end if\then }
  226.                 end;  { end if\then }
  227.  
  228.  
  229.                 { Check for extended keystroke (arrow keys) }
  230.                 if (key=chr(0)) then
  231.                 begin
  232.                      key := readkey;
  233.  
  234.                      { Right Arrow }
  235.                      if (key = #77) then
  236.                      begin
  237.                           StandL:= FALSE;
  238.                           StandR:= FALSE;
  239.                           WalkL := FALSE;
  240.  
  241.                           if (WalkR) then
  242.                           begin
  243.                                WalkR := FALSE;
  244.                                StandR:= TRUE;
  245.                           end  { end if\then }
  246.                           else WalkR := TRUE;
  247.                      end;
  248.  
  249.                      { Left Arrow }
  250.                      if (key = #75) then
  251.                      begin
  252.                           StandL:= FALSE;
  253.                           StandR:= FALSE;
  254.                           WalkR := FALSE;
  255.                           if (WalkL) then
  256.                           begin
  257.                                WalkL := FALSE;
  258.                                StandL := TRUE;
  259.                           end  { end if\then }
  260.                           else WalkL := TRUE;
  261.                      end;
  262.                 end;
  263.            end;
  264.  
  265.            if (StandL) then PutClip (man[1]^, x, y, 25, 39);
  266.            if (StandR) then FlipClip (man[1]^, x, y, 25, 39);
  267.  
  268.            if (WalkL) then
  269.            begin
  270.                 dec(x,speed);
  271.                 PutClipD (man[cnum]^, x, y, 25, 39);
  272.                 inc(cnum);
  273.                 if (cnum > 8) then cnum := 1;
  274.            end;  { end if\then }
  275.  
  276.            if (WalkR) then
  277.            begin
  278.                 inc(x,speed);
  279.                 FlipClip (man[cnum]^, x, y, 25, 39);
  280.                 inc(cnum);
  281.                 if (cnum > 8) then cnum := 1;
  282.            end;  { end if\then }
  283.  
  284.            PutImage (btree^, 33, 64, 73, 83);
  285.  
  286.            { Update mouse cursor }
  287.            MMove;
  288.  
  289.            { Check for mouse button clicks }
  290.            MClick (0);
  291.  
  292.            if (btnP<>0) then
  293.            begin
  294.  
  295.                 if ((btnX < x) and (btnY<166)) then
  296.                 begin
  297.                      StandL:= FALSE;
  298.                      StandR:= FALSE;
  299.                      WalkR := FALSE;
  300.                      if (WalkL) then
  301.                      begin
  302.                           WalkL := FALSE;
  303.                           StandL := TRUE;
  304.                      end  { end if\then }
  305.                      else WalkL := TRUE;
  306.                 end;
  307.  
  308.                 if ((btnX > x) and (btnY<166)) then
  309.                 begin
  310.                      StandL:= FALSE;
  311.                      StandR:= FALSE;
  312.                      WalkL := FALSE;
  313.  
  314.                      if (WalkR) then
  315.                      begin
  316.                           WalkR := FALSE;
  317.                           StandR:= TRUE;
  318.                      end  { end if\then }
  319.                      else WalkR := TRUE;
  320.                 end;
  321.  
  322.                 if (btnX >= 272) and (btnX <= 309) then
  323.                    if (btnY >= 178) and (btnY <= 187) then Quit:=true;
  324.            end;
  325.  
  326.            { Update the video screen }
  327.            Update;
  328.  
  329.      until (Quit);
  330.  
  331.      { Tidy up the loop- make sure the other page is reset }
  332.      Update;
  333.  
  334.      tmpPage := GetWorkPage;
  335.      SetWorkPage (4);
  336.      vprint ('Same demo with manual "page-flipping"!', 10, 150, 1, 255);
  337.      Update;
  338.      Update;
  339.      SetWorkPage (tmpPage);
  340. End;  { Procedure }
  341.  
  342.  
  343.  
  344. { - - - - - - }
  345. Procedure Game_SampleDemo2;
  346. Var
  347.    WalkL, WalkR,
  348.    StandL, StandR   : Boolean;
  349.    Quit             : Boolean;
  350.    fname            : string;
  351.    cnum,
  352.    speed            : byte;
  353.    whichpage        : byte;         { Used for manual page flipping }
  354.  
  355. Begin
  356.      { Allocate memory for keeping track of the background redraw }
  357.      new (backg);
  358.  
  359.      { Make sure the mouse cursor is turned off for the second demo. }
  360.      MShow (0);
  361.  
  362.      if (x < 11) then x := 10;
  363.      if (x > 289) then x := 289;
  364.      cnum  := 1;
  365.      speed := 2;
  366.      StandL:= TRUE;
  367.      StandR:= FALSE;
  368.      WalkL := FALSE;
  369.      WalkR := FALSE;
  370.      Quit  := FALSE;
  371.  
  372.      FlushKB;
  373.      repeat
  374.            if (keypressed) then
  375.            begin
  376.                 key := readkey;
  377.  
  378.                 if (upcase(key) = 'Q') then Quit := TRUE;
  379.  
  380.                 { Increase guy's speed }
  381.                 if (key = '+') then
  382.                 begin
  383.                      inc(speed);
  384.                      if (speed > 3) then
  385.                      begin
  386.                           speed := 3;
  387.                           sound (900);
  388.                           delay (10);
  389.                           nosound;
  390.                      end;  { end if\then }
  391.                 end;  { end if\then }
  392.  
  393.                 { Decrease guy's speed }
  394.                 if (key = '-') then
  395.                 begin
  396.                      dec(speed);
  397.                      if (speed < 1) then
  398.                      begin
  399.                           speed := 1;
  400.                           sound (900);
  401.                           delay (10);
  402.                           nosound;
  403.                      end;  { end if\then }
  404.                 end;  { end if\then }
  405.  
  406.  
  407.                 { Check for extended keystroke (arrow keys) }
  408.                 if (key=chr(0)) then
  409.                 begin
  410.                      key := readkey;
  411.  
  412.                      { Right Arrow }
  413.                      if (key = #77) then
  414.                      begin
  415.                           StandL:= FALSE;
  416.                           StandR:= FALSE;
  417.                           WalkL := FALSE;
  418.  
  419.                           if (WalkR) then
  420.                           begin
  421.                                WalkR := FALSE;
  422.                                StandR:= TRUE;
  423.                           end  { end if\then }
  424.                           else WalkR := TRUE;
  425.                      end;
  426.  
  427.                      { Left Arrow }
  428.                      if (key = #75) then
  429.                      begin
  430.                           StandL:= FALSE;
  431.                           StandR:= FALSE;
  432.                           WalkR := FALSE;
  433.                           if (WalkL) then
  434.                           begin
  435.                                WalkL := FALSE;
  436.                                StandL := TRUE;
  437.                           end  { end if\then }
  438.                           else WalkL := TRUE;
  439.                      end;
  440.                 end;
  441.            end;
  442.  
  443.            if (StandL) then PutImage (man[1]^, x, y, 25, 39);
  444.            if (StandR) then FlipImage (man[1]^, x, y, 25, 39);
  445.  
  446.            if (WalkL) then
  447.            begin
  448.                 dec(x,speed);
  449.                 if (x <= 10) then
  450.                 begin
  451.                      WalkL := FALSE;
  452.                      StandL := TRUE;
  453.                      WalkR := FALSE;
  454.                      StandR := FALSE;
  455.                      x := 11;
  456.                 end;  { end if\then }
  457.                 PutImage (man[cnum]^, x, y, 25, 39);
  458.                 inc(cnum);
  459.                 if (cnum > 8) then cnum := 1;
  460.            end;  { end if\then }
  461.  
  462.            if (WalkR) then
  463.            begin
  464.                 inc(x,speed);
  465.                 if (x > 290) then
  466.                 begin
  467.                      WalkR := FALSE;
  468.                      StandR := TRUE;
  469.                      WalkL := FALSE;
  470.                      StandL := FALSE;
  471.                      x := 289;
  472.                 end;  { end if\then }
  473.                 FlipImage (man[cnum]^, x, y, 25, 39);
  474.                 inc(cnum);
  475.                 if (cnum > 8) then cnum := 1;
  476.            end;  { end if\then }
  477.  
  478.            PutImage (btree^, 33, 64, 73, 83);
  479.  
  480.            { Update the video screen }
  481.            whichpage := GetWorkPage;
  482.            SetWorkPage (4);
  483.            GetImage (backg^, (x - speed), y, 25, 39);
  484.  
  485.            if (whichpage = 1) then
  486.            begin
  487.                 showpage (1);
  488.                 SetWorkPage (2);
  489.                 PutImage (backg^, (x - speed), y, 25, 39);
  490.            end
  491.            else
  492.            begin
  493.                 showpage (2);
  494.                 SetWorkPage (1);
  495.                 PutImage (backg^, (x - speed), y, 25, 39);
  496.            end;  { else }
  497.  
  498.      until (Quit);
  499.  
  500.      FadeOut (1, 1, 0);
  501.  
  502.      { Clear the video pages }
  503.      SetWorkPage (1);
  504.      clearscreen (0);
  505.      SetWorkPage (2);
  506.      clearscreen (0);
  507.  
  508.      { Restore the palette }
  509.      RestorePalette;
  510.  
  511.  
  512.      { Free the memory we allocated earlier }
  513.      dispose (backg);
  514.      dispose (btree);
  515.  
  516.      for tmp := 1 to 8 do
  517.          dispose (man[tmp]);
  518.  
  519. End;  { Procedure }
  520.  
  521.  
  522.  
  523. { ************************** }
  524. {      Main Procedure        }
  525. { ************************** }
  526. Begin
  527.      { Tell VGFX to use DEMO.GFX for all it's file handling }
  528.      SetWorkLib ('demo.gfx');
  529.  
  530.      { Initialize VGFX }
  531.      VGFX_Init;
  532.  
  533.  
  534.      { Set Palette to Black }
  535.      BlankPalette;
  536.  
  537.      { Do the demo! }
  538.      Game_SampleDemo;
  539.      Game_SampleDemo2;
  540.  
  541.      { Shut-down VGFX and clean up it's mess }
  542.      VGFX_Done;
  543. End.  { Program }
  544.